package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormHistoryPrice;
import com.movitech.mobile.cz.base.purchase.mapper.WFlowFormHistoryPriceMapper;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormHistoryPriceService;
import com.movitech.mobile.cz.base.util.UserUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 流程表单-历史价格水平 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@Service
public class WFlowFormHistoryPriceServiceImpl extends ServiceImpl<WFlowFormHistoryPriceMapper, WFlowFormHistoryPrice> implements WFlowFormHistoryPriceService {
    @Override
    public List<WFlowFormHistoryPrice> getByFlowFormId(String wflowFormId) {
        EntityWrapper entityWrapper =new EntityWrapper<>();
        WFlowFormHistoryPrice wFlowFormHistoryPrice = new WFlowFormHistoryPrice();
        wFlowFormHistoryPrice.setFlowFormId(wflowFormId);
        wFlowFormHistoryPrice.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
        entityWrapper.setEntity(wFlowFormHistoryPrice);
       return selectList(entityWrapper);
    }

    @Override
    public RestReturnResult addHistoryPriceService(WFlowFormHistoryPrice wFlowFormHistoryPrice) {
    	
        wFlowFormHistoryPrice.setBaseFeilds(UserUtils.getCurrentUserId(),null,0,true);
        boolean flag = insert(wFlowFormHistoryPrice);
        
        if(flag){
        	return new RestReturnResult(CommonConstants.SUCCESS, wFlowFormHistoryPrice);
        }else{
        	return new RestReturnResult(CommonConstants.FAIL, wFlowFormHistoryPrice);
        }
        
    }
}
